-- @owner: @zhanghuan96
-- @date: 2024/12/16
-- @testpoint: gms_utility.exec_ddl_statement，语句为创建、修改、删除自定义函数，部分合理报错
@conn PrimaryDbAmode;
--前置条件
drop extension if exists gms_utility cascade;
create extension gms_utility;
set behavior_compat_options='bind_procedure_searchpath';
--step1:自定义函数中建表;expect:成功
call gms_utility.exec_ddl_statement('CREATE OR REPLACE FUNCTION public.create_database_example(db_name text)
RETURNS void AS $$
BEGIN
    EXECUTE format(''CREATE table public.%I(a int);'', db_name);
END;
$$ LANGUAGE plpgsql;');
--step2:exec_ddl_statement语句为执行自定义函数;expect:报错
call gms_utility.exec_ddl_statement('call public.create_database_example(''t_exec0014'')');
--step3:调用存储过程;expect:成功
call public.create_database_example('t_exec0014');
--step4:修改函数的执行规则为IMMUTABLE;expect:成功
call gms_utility.exec_ddl_statement('ALTER FUNCTION public.create_database_example(text) IMMUTABLE');
--step5:修改函数名称;expect:成功
call gms_utility.exec_ddl_statement('ALTER FUNCTION public.create_database_example(text) RENAME TO create_database_example_new;');
--step6:删除函数;expect:成功
call gms_utility.exec_ddl_statement('drop function public.create_database_example_new');
--step7:清理环境;expect:成功
drop table public.t_exec0014;
drop extension if exists gms_utility cascade;
reset behavior_compat_options;